<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ProceedList;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ProceedListController extends AdminController
{
    protected $status = [1 => '待结算', 2 => '已结算', 3 => '已失效'];

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ProceedList(['user', 'order']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user.username');
            $grid->column('order.amount');
            $grid->column('status')->using($this->status)->label([
                1 => Admin::color()->gray(),
                2 => Admin::color()->green(),
                3 => Admin::color()->red(),
            ]);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('user.username')->width(3);
                $filter->like('order.order_number')->width(3);
            });
            $grid->disableCreateButton();
            $grid->disableActions();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ProceedList(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('order_id');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ProceedList(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('order_id');
            $form->text('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
